﻿Imports ControleMatricula.Negocio

Public Class FrmPagamentoConsultar
    Dim db As New DataClassesDataContext()
    Friend RowPagamento As SPPagamentoConsultarResult

    Private Sub btnConsultar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Dim retorno As List(Of SPPagamentoConsultarResult)

        If IsNumeric(txtConsulta.Text) Then
            Dim id As Integer
            id = Convert.ToInt32(txtConsulta.Text)
            retorno = db.SPPagamentoConsultar(id, "").ToList()
        Else
            retorno = db.SPPagamentoConsultar(0, txtConsulta.Text).ToList()
        End If

        listPagamento.DataSource = retorno
        listPagamento.DisplayMember = "DEPagamento"
        listPagamento.ValueMember = "IDPagamento"

        listPagamento.Focus()
    End Sub

    Sub Selecionar()

        Try
            Dim Retorno As List(Of SPPagamentoConsultarResult)
            Retorno = db.SPPagamentoConsultar(listPagamento.SelectedValue, "").ToList()

            RowPagamento = Retorno(0)

            Me.Close()

        Catch Er As Exception
            MsgBox(Er.Message, MsgBoxStyle.Critical, "Específica")
        Finally
            Me.Cursor = System.Windows.Forms.Cursors.Default
        End Try


    End Sub

    Private Sub listPagamento_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles listPagamento.KeyDown
        If listPagamento.Items.Count > 0 Then
            If e.KeyData = Keys.Enter Then
                Call Selecionar()
            End If
        End If
    End Sub

    Private Sub listPagamento_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles listPagamento.MouseUp
        If listPagamento.Items.Count > 0 Then
            Call Selecionar()
        End If
    End Sub

    Private Sub txtConsulta_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtConsulta.KeyDown
        If e.KeyData = Keys.Enter Then
            btnConsultar_Click(sender, e)
        End If
    End Sub

    Private Sub txtConsulta_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtConsulta.TextChanged
        If txtConsulta.Text <> "" Then
            If Not IsNumeric(txtConsulta.Text) Then
                Label1.Text = "Descrição"
            Else
                Label1.Text = "Código"
            End If
        Else
            Label1.Text = "Código / Descrição"
        End If
    End Sub
End Class